package com.example.shengyin.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotBlank;
import java.sql.Timestamp;
import java.util.Date;

/**
 * @author oldliu
 * @since 1.0
 */
@Data
@ApiModel("分页查询")
public class Page{
    public static final int PAGESIZE=10;
    private int code=0;
    private Object data;
    @NotBlank(message = "当前页数不能为空")
    @Range(min = 1,message = "页数大小不能小于零")
    @ApiModelProperty("页数")
    private int page=1;
    private int count;//总数
    private int pageTotal;//总页数
    @NotBlank(message = "一页的数据条数不能为空")
    @Range(min = 1,message = "数据条数大小不能小于1")
    @ApiModelProperty("数据条数")
     int limit;

    public Page(Object data) {
        this.data = data;
    }

    public Page(){

    }
    public Page(Object data, int total, int limit) {
        this.data = data;
        this.setCount(total);
        this.limit = limit;
    }
    public Page(Object data, int page, int total, int limit) {
        this.data = data;
        this.page = page;
        this.limit = limit;
        this.setCount(total);

    }
    public Page(int page,int limit) {
        this.data = data;
        this.page = page;
        this.limit = limit;

    }
    public void setCount(int count) {
        this.count = count;
        this.pageTotal = this.count / this.limit + (this.count % this.limit == 0 ? 0 : 1);
    }


}
